package com.zx.练习题.demo;

import java.util.Arrays;
import java.util.Random;
import java.util.stream.IntStream;

public class Demo8 {

    //5.随机填充一个length为100的int数组，使用冒泡排序法对该数组进行升序排序，并打印排序后的结果
    public static void main(String[] args) {
        int[] arr = new int[100];

        Random random = new Random();
        IntStream.range(0, 100).forEach(i -> arr[i] = random.nextInt(100));

        for (int i = 0; i < arr.length; i++) {
            boolean isLoop = false;
            for (int j = 0; j < arr.length - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    int t = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = t;
                    isLoop = true;
                }
            }
            if (!isLoop) {
                break;
            }
        }

        System.out.println(Arrays.toString(arr));
    }
}
